/*
 * PKL 51 GUNUNG KIDUL
 * Subseksie DATA ENTRY + CAPI
 */
package pkl51.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import pkl51.entity.Blok6b;
import pkl51.error.EntityException;
import pkl51.service.Blok6bDao;
import pkl51.service.impl.Blok6bDaoImpl;

/**
 *
 * @author toshiba
 */
public class Blok6bRowModel implements Serializable{
    private static final long serialVersionUID = -2862022423965489644L;

    private String nks;
    private String idPangan;
    private String b6BC1 = "";
    private String b6BC2 = "";
    private String b6BC3 = "";
    private String b6BC4 = "";
    private String b6BC5 = "";
    private PropertyChangeSupport propertySupport;

    public Blok6bRowModel() {
        this.nks = Blok123Model.getInstance().getNKS();
        propertySupport = new PropertyChangeSupport(this);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }

    public void insertBlok6bRow(int id) throws EntityException {
        this.nks = Blok123Model.getInstance().getNKS();
        idPangan = String.valueOf(id);
        Blok6bDao blok6bDao = new Blok6bDaoImpl();
        blok6bDao.insertBlok6b(new Blok6b(nks, idPangan,
                Double.valueOf(b6BC1),
                Integer.valueOf(b6BC2),
                Double.valueOf(b6BC3),
                Integer.valueOf(b6BC4),
                Double.valueOf(b6BC5)));

    }

    public void updateBlok6bRow(int id) throws EntityException {
        this.nks = Blok123Model.getInstance().getNKS();
        idPangan = String.valueOf(id);
        Blok6bDao blok6bDao = new Blok6bDaoImpl();
        blok6bDao.updateBlok6b(new Blok6b(nks, idPangan, Double.valueOf(b6BC1), Integer.valueOf(b6BC2), Double.valueOf(b6BC3), Integer.valueOf(b6BC4), Double.valueOf(b6BC5)));

    }

    public void getBlok6bRow(int id) throws EntityException {
        this.nks = Blok123Model.getInstance().getNKS();
        idPangan = String.valueOf(id);
        Blok6bDao blok6bDao = new Blok6bDaoImpl();
        Blok6b blok6b = blok6bDao.getBlok6bByNKS_IdPangan(nks, idPangan);

        setIdPangan(blok6b.getID_PANGAN());
        setB6BC1(String.valueOf(blok6b.getB6BC1()));
        setB6BC2(String.valueOf(blok6b.getB6BC2()));
        setB6BC3(String.valueOf(blok6b.getB6BC3()));
        setB6BC4(String.valueOf(blok6b.getB6BC4()));
        setB6BC5(String.valueOf(blok6b.getB6BC5()));

        if (blok6b.getB6BC1() == 0.00 && blok6b.getB6BC3() == 0.00 && blok6b.getB6BC5() == 0.00) {
            setB6BC1(null);
            setB6BC2(null);
            setB6BC3(null);
            setB6BC4(null);
            setB6BC5(null);
        }
    }

    public void resetModel(){
        setB6BC1("");
        setB6BC2("");
        setB6BC3("");
        setB6BC4("");
        setB6BC5("");
    }
    
    public void setNks(String nks) {
        String old = this.nks;
        this.nks = nks;
        propertySupport.firePropertyChange("nks", old, this.nks);
    }

    public void setIdPangan(String idPangan) {
        String old = this.idPangan;
        this.idPangan = idPangan;
        propertySupport.firePropertyChange("idPangan", old, this.idPangan);
    }

    public void setB6BC1(String b6BC1) {
        String old = this.b6BC1;
        this.b6BC1 = b6BC1;
        propertySupport.firePropertyChange("b6BC1", old, this.b6BC1);
    }

    public void setB6BC2(String b6BC2) {
        String old = this.b6BC2;
        this.b6BC2 = b6BC2;
        propertySupport.firePropertyChange("b6BC2", old, this.b6BC2);
    }

    public void setB6BC3(String b6BC3) {
        String old = this.b6BC3;
        this.b6BC3 = b6BC3;
        propertySupport.firePropertyChange("b6BC3", old, this.b6BC3);
    }

    public void setB6BC4(String b6BC4) {
        String old = this.b6BC4;
        this.b6BC4 = b6BC4;
        propertySupport.firePropertyChange("b6BC4", old, this.b6BC4);
    }

    public void setB6BC5(String b6BC5) {
        String old = this.b6BC5;
        this.b6BC5 = b6BC5;
        propertySupport.firePropertyChange("b6BC5", old, this.b6BC5);
    }

    public String getNks() {
        return nks;
    }

    public String getIdPangan() {
        return idPangan;
    }

    public String getB6BC1() {
        return b6BC1;
    }

    public String getB6BC2() {
        return b6BC2;
    }

    public String getB6BC3() {
        return b6BC3;
    }

    public String getB6BC4() {
        return b6BC4;
    }

    public String getB6BC5() {
        return b6BC5;
    }
    
}
